//
//  ZSY_SearchTableViewCell.m
//  ZSY_BreadTrip
//
//  Created by 张诗宇 on 16/1/6.
//  Copyright © 2016年 张诗宇. All rights reserved.
//

#import "ZSY_SearchTableViewCell.h"
#import "ZSY_SearchCollectionViewCell.h"
#import "ZSY_SearchModel.h"

@interface ZSY_SearchTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) ZSY_CollectionView *myCollectionView;

@property (nonatomic, retain) ZSY_SearchCollectionViewCell *cell;
@property (nonatomic, retain) UICollectionViewFlowLayout *flowLayout;

@end

@implementation ZSY_SearchTableViewCell


- (void)dealloc {
    [_myCollectionView release];
    [_allArray release];
    [super dealloc];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setAllArray:(NSMutableArray *)allArray {
    if (_allArray != allArray) {
        [_allArray release];
        _allArray = [allArray retain];
    }
    _myCollectionView.frame = CGRectMake(0, 0, WIDTH, 30 * _allArray.count + 30);
    [self.myCollectionView reloadData];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
//    self.contentView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:243 / 255.0 blue:233 / 255.0 alpha:1];
    
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    _flowLayout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
    
    _flowLayout.itemSize = CGSizeMake(WIDTH / 2, 20);
    
    self.myCollectionView = [[ZSY_CollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 300) collectionViewLayout:_flowLayout];
    
    self.myCollectionView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:243 / 255.0 blue:233 / 255.0 alpha:0];
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    [self.contentView addSubview:_myCollectionView];
    [self.myCollectionView registerClass:[ZSY_SearchCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [_myCollectionView release];
    [_flowLayout release];
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    self.cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    ZSY_SearchModel *model = [_allArray objectAtIndex:indexPath.row];
    _cell.search = model;
    return _cell;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _allArray.count;
}

@end
